<template>
  <div>
    <div>
      <img :src="imgSrc" />
    </div>
    <el-divider content-position="left">业务信息</el-divider>
        <div >
          <el-form :model="businessForm" ref="businessForm" label-width="140px" class="demo-ruleForm" size="mini" inline>
            <my-form-item v-for="item in formlist" :label="item.name" :key="item.id">
                <el-input v-model="businessForm[item.value]" disabled></el-input>
            </my-form-item>
        </el-form>
    </div>
    <div class v-if="checkList.length!=0" v-for="(item,index) in checkList" :key="item.id">
      <el-divider content-position="left">{{item.taskName}}</el-divider>
      <div>
        <el-form label-width="140px" class="demo-ruleForm" size="mini" inline>
          <my-form-item
            v-for="item1 in checkList[index].formInfo"
            :label="item1.name"
            :key="item1.id"
          >
            <el-input v-model="checkList[index].checkInfo[item1.value]" disabled></el-input>
          </my-form-item>
        </el-form>
      </div>
    </div>

    
    <el-divider content-position="left">审批信息</el-divider>
    <div>
      <el-form
        :model="ruleForm"
        ref="ruleForm"
        label-width="140px"
        class="demo-ruleForm"
        size="mini"
        inline
      >
        <my-form-item v-for="item in list" :label="item.name" :key="item.id">
          <el-input v-model="ruleForm[item.value]"></el-input>
        </my-form-item>
      </el-form>
      <div style="text-align:center">
        <el-button size="mini" type="primary" @click="submit()">提交</el-button>
      </div>
    </div>
  </div>
</template>
  
  <script>

export default {
  components: {},
  data() {
    return {
      list: [],
      ruleForm: {},
      businessForm: {},
      formlist: [],
      imgSrc: '',
      checkList: [],
    };

  },

  mounted() {
    this.innit();
  },
  computed: {
  },

  methods: {
    search() {
      let params = {
        processInstanceId: this.$route.query.instId,
      }
      this.$api
        .formPost("/api/flowact/commTaskassignee/findPicture", params)
        .then(res => {
          if (res.retHead.code == "0000000") {
            this.imgSrc = "data:image/png;base64," + res.retBody;
          } else {
            this.$message({
              message: res.retHead.message,
              type: "error"
            });
          }
        });
    },
    submit() {
      let user = JSON.parse(sessionStorage.getItem("user"));
      let params = {
        userName: user.realName,
        userId: user.id,
        taskId: this.$route.query.id,
        taskName: this.$route.query.taskName,
        businessId: this.$route.query.businessId,
        formInfo: JSON.stringify(this.list),
        checkInfo: JSON.stringify(this.ruleForm)
      }
      this.$api
        .formPost("/api/flowact/flow/approve", params)
        .then(res => {
          if (res.retHead.code == "0000000") {
            this.$message({
              message: "提交成功",
              type: "success"
            });
            this.$router.push("/activity/myTask");
          } else {
            this.$message({
              message: res.retHead.message,
              type: "error"
            });
          }
        });
    },
    innit() {
      this.search();
      this.getform();
      this.getbusinessInfo();
      this.getcheckList();
    },
    getform() {
      let params = { taskId: this.$route.query.id }
      this.$api
        .formPost("/api/flowact/commTaskForm/findListByTaskId", params)
        .then(res => {
          if (res.retHead.code == "0000000") {
            this.list = res.retBody;
          } else {
            this.$message({
              message: res.retHead.message,
              type: "error"
            });
          }
        });
    },
    getbusinessInfo() {
      let params = { id: this.$route.query.businessId }
      this.$api
        .formPost("/api/flowact/Business/doGetBusinessById", params)
        .then(res => {
          if (res.retHead.code == "0000000") {
            this.formlist = JSON.parse(res.retBody.formInfo);
            this.businessForm = JSON.parse(res.retBody.businessInfo);
          } else {
            this.$message({
              message: res.retHead.message,
              type: "error"
            });
          }
        });
    },
    getcheckList() {
      let params = { businessId: this.$route.query.businessId }
      this.$api
        .formPost("/api/flowact/businessCheck/doGetcheckList", params)
        .then(res => {
          if (res.retHead.code == "0000000") {
            this.checkList = res.retBody;
            this.checkList.forEach(item => {
              item.formInfo = JSON.parse(item.formInfo);
              item.checkInfo = JSON.parse(item.checkInfo);
            })

          } else {
            this.$message({
              message: res.retHead.message,
              type: "error"
            });
          }
        });
    }
  },
  created() { }
};
  </script>
  <style lang='scss' scoped>
</style>